/********************************************************************************
 *      Copyright:  (C) 2022 Zhang Changxing<ZhangChangxingVIP@163.com>
 *                  All rights reserved.
 *
 *       Filename:  database.h
 *    Description:  This head file 
 *
 *        Version:  1.0.0(04/13/2022)
 *         Author:  Zhang Changxing <ZhangChangxingVIP@163.com>
 *      ChangeLog:  1, Release initial version on "04/13/2022 01:35:13 AM"
 *                 
 ********************************************************************************/


#ifndef  _DATABASE_H_
#define  _DATABASE_H_

#include "main.h"

/*
 *   description:   Database initialization, open the database
 *          args:   $dbname:    Path and name of the database that you want to open
 *  return value:   <0: failure,    =0:ok 
 */
int sqlite_init(char *dbname);

/*
 *   description:   Creates a table for the database, or does not create one if it exists
 *          args:   $table_name:    The name of the table created
 *  return value:   <0: failure,    =0:ok 
 */
int sqlite_create_table(char *table_name);

/*
 *   description:   Insert the data that failed to send into the table of the database
 *          args:   $pack_info:     Packet structure
 *                  $table_name:    Database table name
 *  return value:   <0: failure,    =0:ok 
 */
int data_insert(pack_info_t pack_info, char *table_name);

/*
 *   description:   Delete the first data in the database
 *          args:   $table_name:    Database table name
 *  return value:   <0: failure,    =0:ok 
 */
int data_delete(char *table_name);

/*
 *   description:   Find the first data from table_name in the database and store it in the pack_info structure
 *          args:   $pack_info:     Packet structure
 *                  $table_name:    Database table name
 *  return value:   <0: failure,    =0:ok 
 */
int select_first_data(pack_info_t *pack_info,  char *table_name);

/*
 *   description:   Check whether the table is empty
 *          args:   $table_name:    Database table name
 *  return value:   <0: failure,    =0:ok 
 */
int check_table_data(char *table_name);

/*
 *   description:   Determine whether the database is still in use and shut down the database
 *  return value:   <0: failure,    =0:ok 
 */
int close_database(void);

#endif   /* ----- #ifndef _DATABASE_H_  ----- */


